Fix "exists" matching as many times as there are duplicates in an array of values #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Operands (and, or, bool) work by maintaining a counter of different conditions that must all be met before a subfilter can match.
That counter should only be decremented once per tested condition on any given subfilter.
But when testing an array of values with
exists
, the exists matcher decrements the counter without verifying if the condition has already been verified.For instance, the following condition:
exists: foo["bar"]
matches 2 times if the following object is tested:{"foo": ["bar", "bar"]}
And, if it's used in an operand waiting for, say, 2 different conditions, then that keyword can validate the entire operand by itself, even if the other condition is not verified.
This bug has been solved by making the exists matcher test only a set of unique values extracted from the array.
I checked the other matchers and they seem unaffected by this bug.
fix #24
How to review
I dusted off the code a bit while I was reading the test files, so there are a lot of cosmetic changes that can be ignored in the unit test files.
Just ignore them, nothing changed in these files, except for one new test that I pointed with a comment so that you can easily find where it is.